package com.glsc.ngateway.platform.service.easyflow;


import com.alibaba.fastjson.JSONObject;
import com.glsc.ngateway.common.api.common.enums.RabbitExcQueConstant;
import com.glsc.ngateway.platform.service.easyflow.dto.WorkflowMsgDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class EasyFlowMessageSender {

    private static final Logger logger = LoggerFactory.getLogger(EasyFlowMessageSender.class);

    @Resource
    private AmqpTemplate rabbitTemplate;

    /**
     * @param workflowMsgDto 工作流程消息信息
     */
    public void sendMessage(WorkflowMsgDto workflowMsgDto) {

        String context = JSONObject.toJSONString(workflowMsgDto);
        logger.info("EasyFlowMessageSender 开始发送消息：context :  " + context);

        try {
            //保存消息至数据库 TODO
        } catch (Exception e) {

        }
        rabbitTemplate.convertAndSend(RabbitExcQueConstant.EXCHANGE_EASY_FLOW_MSG, RabbitExcQueConstant.GATEWAY_QUEUE_EASY_FLOW_MSG, context);
    }
}
